﻿using System.Collections.Generic;
using System.Xml;

namespace ExportWordBibModule.SchemaImplementation
{
    /// <summary>
    /// Bibliography sources
    /// </summary>
    public class Sources
    {
        const string ns = Constants.BibliographyNamespace;
        const string b = Constants.BibliographyPrefix;

        public List<Source> Source = new List<Source>();

        /// <summary>
        /// Renders the sources as XML.
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            XmlDocument document = new XmlDocument();
            var declaration = document.CreateXmlDeclaration("1.0", string.Empty, string.Empty);

            
            var rootnode = document.CreateElement(b, "Sources", ns);
            document.AppendChild(rootnode);
            foreach (var source in Source)
            {
                var sourceNode = source.Render();
                var sourceNodeImported = document.ImportNode(sourceNode, true);
                rootnode.AppendChild(sourceNodeImported);
            }

            return string.Format("{0}\n{1}", declaration.InnerXml, document.InnerXml);
        }
    }
}
